

package com.example.ItPhotoAlbumCloud.utils;

//import com.sun.xml.internal.stream.buffer.sax.Properties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/*

AppConfig.java - 配置类
该类包含了 RedisTemplate 和 JavaMailSender 的配置信息。
RedisTemplate 配置了 Redis 数据库的连接工厂和 key-value 的序列化方式。
JavaMailSender 配置了发送邮件所需的参数和属性。
*/
@Configuration
public class AppConfig {

    // 配置 RedisTemplate
    @Bean
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory connectionFactory) {
        RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(connectionFactory);
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        return redisTemplate;
    }

    // 配置 JavaMailSender
    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
        javaMailSender.setHost("smtp.qq.com");
        javaMailSender.setPort(587);
        javaMailSender.setUsername("3433087132@qq.com");
        javaMailSender.setPassword("dxnhkbdmmxrvdcbi");
        javaMailSender.setJavaMailProperties(getMailProperties());
        return javaMailSender;
    }

//     配置 JavaMailSender 所需的属性
    private Properties getMailProperties() {
        Properties properties = new Properties();
        properties.setProperty("mail.smtp.auth", "true");
        properties.setProperty("mail.smtp.starttls.enable", "true");
        return properties;
    }
}